#!/bin/bash
# 部署脚本
# 用法: ./deploy.sh [test|prod]

set -e

ENV=${1:-test}

if [[ "$ENV" != "test" && "$ENV" != "prod" ]]; then
  echo "错误: 环境必须是 test 或 prod"
  echo "用法: ./deploy.sh [test|prod]"
  exit 1
fi

ECS_HOST="47.106.214.252"
ECS_USER="root"
SSH_KEY="$HOME/.ssh/pokermind-ai-test.pem"
REMOTE_DIR="/data/apps/pokermind-tcp"
JAR_NAME="pokermind-tcp.jar"

echo "=== 部署环境: $ENV ==="

echo "=== 编译项目 ==="
cd ..
mvn clean package -DskipTests -Dmaven.test.skip=true -pl pokermind-serv-dse-tcp -am

echo ""
echo "=== 上传JAR ==="
cd pokermind-serv-dse-tcp
scp -i "$SSH_KEY" target/pokermind-serv-dse-tcp-*.jar "$ECS_USER@$ECS_HOST:$REMOTE_DIR/$JAR_NAME"

echo ""
echo "=== 重启应用 ==="
ssh -i "$SSH_KEY" "$ECS_USER@$ECS_HOST" "cd $REMOTE_DIR && ./start.sh $ENV"

echo ""
echo "✓ 部署完成 ($ENV)！"


